function plot_scatter(logPlotFlag,indicesToPlot,numbins,numScaledBins,params,data1,data2)
plot_fig=figure;
parameters.print='true';
%parameters.print='false';
output_dir='C:\Users\Michael Ferry\grants\SBIR\NSF SBIR December 2010\Figures\raw_files\';
% xplotRange=[1.5 log10(2^18)];
% yplotRange=[1.5 log10(2^18)];
 xplotRange=[0 500];
 yplotRange=[0 800];
 
labelFS=8;
axisFS=6;
printedXsize=4;
printedYsize=4;


% yfpIndex=4;
% rfpIndex=5;
% yfpcutoff=3000;
% rfpcutoff=4500;
% gate=data1>yfpcutoff | data2>rfpcutoff;
% data1=data1(gate);
% data2=data2(gate);

set(gcf, 'PaperUnits', 'centimeters');
set(gcf, 'PaperSize', [printedXsize printedYsize]);
set(gcf, 'PaperPositionMode', 'manual');
set(gcf, 'PaperPosition', [0 0 printedXsize printedYsize]);
%set(gca,'FontName','Times-Roman','FontSize',axisFS);

binReduction=numbins/numScaledBins;
dens = zeros(numScaledBins,numScaledBins);

%This rebins the data, by increasing the count in an index of a matix.
%The bins are resized so the matix is not incredibly large

if(logPlotFlag)
    processedData1=log10(data1)*(numScaledBins/log10(numbins));
    processedData2=log10(data2)*(numScaledBins/log10(numbins));
    for i=1:length(data1)
       % x = max(fix(log(data1(i))*(numScaledBins/log(numbins))),1);
        x = max(fix(processedData1(i)),1);
        y = max(fix(processedData2(i)),1);
        %y = max(fix(log(data2(i))*(numScaledBins/log(numbins))),1);
        dens(y,x) = dens(y,x) + 1;
    end    
    %fsc_axis = 0:1:(numScaledBins-1)*binReduction;
    %fl1_axis = 0:1:(numScaledBins-1)*binReduction;
    fsc_axis = [0:1:(numScaledBins-1)]*(log10(numbins))/numScaledBins;
    fl1_axis=fsc_axis;
    toPlotX=findPlottedIndices(fsc_axis,xplotRange);
    toPlotY=findPlottedIndices(fl1_axis,yplotRange);
    gca=imagesc(fsc_axis(toPlotX), fl1_axis(toPlotY), log(dens(toPlotY,toPlotX)+1), [0 5]);
    %fl1_axis = [0:1:(numScaledBins-1)]*(log10(yrange(2))/ybins)
else
    for i=1:length(data1)
        x = max(fix(data1(i)/binReduction),1);
        y = max(fix(data2(i)/binReduction),1);
        dens(y,x) = dens(y,x) + 1;
    end
    fsc_axis = [0:1:(numScaledBins-1)]*binReduction;
    fl1_axis = [0:1:(numScaledBins-1)]*binReduction;
    toPlotX=findPlottedIndices(fsc_axis,xplotRange);
    toPlotY=findPlottedIndices(fl1_axis,yplotRange);
    
    gca=imagesc(fsc_axis(toPlotX), fl1_axis(toPlotY), log(dens(toPlotY,toPlotX)+1), [0 6]);
end


axis xy
% xlabel([params.par(indicesToPlot(1)).name,' v:',num2str(params.par(indicesToPlot(1)).voltage)]);
% ylabel([params.par(indicesToPlot(2)).name,' v:',num2str(params.par(indicesToPlot(2)).voltage)]);
% title([params.experiment,' ', params.specimen,' ',params.tube,': '...
%     params.par(indicesToPlot(1)).name,' vs ',params.par(indicesToPlot(2)).name, ' scatter']);

xlabel('Forward Scatter (A.U.)','FontName','Times-Roman','FontSize',labelFS);
ylabel('GFP Fluor (A.U.)','FontName','Times-Roman','FontSize',labelFS);
title('Control','FontName','Times-Roman','FontSize',labelFS);
aHand=get(plot_fig,'CurrentAxes');

set(aHand,'FontName','Times-Roman','FontSize',axisFS)


if(strcmp(parameters.print,'true'))
    print(plot_fig, '-depsc2', [output_dir datestr(now,30)]);
end


function [toPlot]=findPlottedIndices(PlotAxis,plotRangeForAxis)
toPlot=PlotAxis>plotRangeForAxis(1) & PlotAxis<plotRangeForAxis(2);